//
//  TopMessageView.m
//  WOFishingBoat
//
//  Created by 郑逸凯 on 2019/1/11.
//  Copyright © 2019年 郑逸凯. All rights reserved.
//

#import "TopMessageView.h"

@interface TopMessageView ()
@property (nonatomic,strong)UIImageView *imageView;
@property (nonatomic,strong)UILabel *messageLabel;

@end
@implementation TopMessageView

+ (instancetype)sharedInstance {
    static TopMessageView *_sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedInstance = [[self alloc] init];
    });
    return _sharedInstance;
}

- (instancetype)init {
    if (self = [super init]) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.shadowOffset = CGSizeMake(0,3);
        self.layer.shadowOpacity = 1;
        self.layer.shadowRadius = 5;
        [self addSubview:self.imageView];
        [self addSubview:self.messageLabel];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat topHeight = Height_StatusBar - 20;
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, topHeight + 50);
    self.imageView.frame = CGRectMake(15, topHeight + 13, 25, 25);
    self.messageLabel.frame = CGRectMake(CGRectGetMaxX(self.imageView.frame) + 11, topHeight + 18, SCREEN_WIDTH - CGRectGetMaxX(self.imageView.frame) - 11, 14);
}

//- (void)showMessage:(NSString *)msg {
//    
//}
//
//- (void)showMessage:(NSString *)msg timer:(int)aTimer {
//    
//}

- (void)showForeverMessage:(NSString *)msg {
    self.messageLabel.text = msg;
    [[UIApplication sharedApplication].keyWindow addSubview:self];
}

- (void)hide {
    [self removeFromSuperview];
}

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top_alarm_icon"]];
    }
    return _imageView;
}

- (UILabel *)messageLabel {
    if (!_messageLabel) {
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(50.5,18,242,14);
        label.textColor = RGB16(0x333333);
        label.font = [UIFont systemFontOfSize:14];
        label.text = @"当前网络不可用，请检查你的网络设置。";
        _messageLabel = label;
//        _messageLabel =
    }
    return _messageLabel;
}

@end
